package com.handinfo.android.core.ui;

import android.content.Context;
import android.graphics.Canvas;
import android.view.View;
import android.widget.Button;

public class UIButton extends Button
{
	//是否按下按钮
	public static boolean m_clickable = false;
	public int m_buttonX;
	public int m_buttony;
	public int m_buttonW;
	public int m_buttonH;
	public int m_buttonColor;
	public String m_buttonText;

//	LindearLayout  tp = new LindearLayout  (this);

	public UIButton(Context context)
	{
		super(context);

	}

	//初始化
	public void init(int x, int y, int w, int h, int color)
	{
		this.m_buttonColor = color;
		this.m_buttonX = x;
		this.m_buttony = y;
		this.m_buttonW = w;
		this.m_buttonH = h;
	}

	//是否能被点击
	public void setClickable(boolean clickable)
	{
		if (clickable == false) {
			m_clickable = false;
		}
		if (clickable == true) {
			m_clickable = true;
		}
	}

	//点击按钮按钮变化(宽，高)
	public void changeButtonSize(View view, int w, int h)
	{

		Button button = (Button) view;
		if (m_clickable == true) {
			button.setWidth(w);
			button.setHeight(h);
		}
		if (m_clickable == false) {
			button.setWidth(m_buttonW);
			button.setHeight(m_buttonH);
		}
	}

	//改变按钮上的字体
	public void changeButtonText(View view, String str)
	{
		Button button = (Button) view;
		if (m_clickable == true) {
			button.setText(str);
		}
		if (m_clickable == false) {
			button.setText(m_buttonText);
		}
	}

	//改变按钮背景颜色
	public void changeButtonColor(View view, int color)
	{
		Button button = (Button) view;
		if (m_clickable == true) {
			button.setBackgroundColor(color);
		}
		if (m_clickable == false) {
			button.setBackgroundColor(m_buttonColor);
		}
	}

	//绘制普通按钮
	public void onDraw(Canvas canvas, View view, int textsize, int textcolor, int x, int y, int w, int h,
			int buttoncolor)
	{
		super.onDraw(canvas);
		Canvas c = canvas;
		Button button = (Button) view;
//		Paint paint = new Paint();
		//设置字体大小
		button.setTextSize(textsize);
		//设置字体染色
		button.setTextColor(textcolor);
		//设置宽
		button.setWidth(w);
		//设置高
		button.setHeight(h);
		//设置按钮背景颜色
		changeButtonColor(view, buttoncolor);

	}

//	//绘制ImageButton按钮
//	public void onDraw(Canvas canvas, View view, int x, int y, int w, int h)
//	{
//		Canvas c = canvas;
//		ImageButton ib = (ImageButton) view;
//		Paint paint = new Paint();
//
//	}

	//事件处理
	public void onClick(View v)
	{

	}

//	//改变按钮的样式
//	
//	private Map<Integer, int[]> drawableIds = new HashMap<Integer, int[]>();
//	
//	public boolean ChangButtonImage(View view, MotionEvent event)
//	{
//		//松开
//		if (event.getAction() == MotionEvent.ACTION_UP)
//		{
//			view.setBackgroundResource(drawableIds.get(view.getId())[0]);
//		}
//		//按下
//		else if (event.getAction() == MotionEvent.ACTION_DOWN)
//			view.setBackgroundResource(drawableIds.get(view.getId())[1]);
//		
//		return false;
//		
//	}
}
